﻿<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <title>模块</title>
</head>

<body>
    <div class="page-container">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <!-- <input type="button" class="btnstyle btnadd" value="新增"
                onclick="_showedit('新增','view.html','0','80%','80%');" />
            <input type="text" class="inputword" title="关键字搜索" placeholder="关键字搜索" value="">
            <input type="button" class="btnsearch" onclick="_readpagedata(1);" value="查询">
            <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a> -->

            <form id="form-search" class="searcharea">
                <input type="button" class="btnstyle btnadd" value="新增"
                    onclick="_showedit('新增','view.html','0','80%','80%');" />
                <input type="text" class="inputword" name="word" title="关键字搜索" placeholder="关键字搜索" value="">
                <span class="title">项目：</span>
                <select name="projectId">
                    <option value="0">未选择</option>
                </select>

                <input type="button" class="btnsearch" onclick="_readpagedata(1);" value="查询">
                <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                    href="javascript:location.replace(location.href);" title="刷新"><i
                        class="Hui-iconfont">&#xe68f;</i></a>
            </form>

        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
                <thead>
                    <tr class="text-c">
                        <th width="50">ID</th>
                        <th class="fleft">服务信息</th>
                        <th >环境</th>
                        <th  class="fleft">描述</th>
                        <th width="70">伸缩</th>
                        <th width="70">升级</th>
                        <th width="80">分布</th>
                        <th width="80">操作</th>
                        <th width="80">伸缩</th>
                        <th width="80">操作</th>
                        <th width="50">编辑</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
        <div id="pagenumarea" class="pagenumarea"></div>
    </div>

    <!--_footer 作为公共模版分离出去-->
    <script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="../lib/jquery.contextmenu/jquery.contextmenu.r2.js"></script>
    <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--/_footer 作为公共模版分离出去-->
    <!--请在下方写此页面业务相关的脚本-->
    <!-- <script type="text/javascript" src="../lib/My97DatePicker/4.8/WdatePicker.js"></script> -->


    <script src="../lib/api.js"></script>
    <link href="../lib/page.min.css" rel="stylesheet" />
    <script src="../lib/page.min.js"></script>

    <script>

        var pageobject = null;

        $(window).ready(function () {

            _readproject(true);

            _readpagedata(1);

            $(".inputword").keyup(function (event) {
                if (event.keyCode == 13) {
                    _readpagedata(1);
                }
            });

            window.addEventListener('message', function (e) {
                if (e.data) {
                    if (e.data.type == "storeid") {
                        var info = e.data.data;
                        if (selectmodelid != 0) {
                            _apipost("/api/spider/manage/buildImage?storeid=" + info.id + "&modelid=" + selectmodelid, true, "", function (code, obj) {
                                if (code == 200) {
                                    layer.msg("构建新的镜像的命令已经发送，可以前往任务列表中查看任务执行结果！");
                                }
                            });
                        }
                    }
                }
            });

        });

        function _readpagedata(page) {

            var inputword = $(".inputword").val();

            if (page == 1) {
                $("#pagenumarea").empty();
            }
            var dataobj = $("#form-search").parseForm();
            dataobj.page = page;
            dataobj.size = 20;

            _apipost("/api/spider/modelInfo/getList", true, JSON.stringify(dataobj), function (code, obj) {
                if (code == 200) {
                    var datas = obj.items;
                    _showpagedata(datas);
                    if (pageobject == null || page == 1) {
                        pageobject = new Page({
                            el: '#pagenumarea',
                            nums: obj.totalCount,//总数
                            counts: 20,//每页大小
                            defaultPage: 1,
                            showHeadFoot: false, // 显示首页尾页
                            head: '首', // 更改首页文字
                            foot: '尾', // 更改尾页文字
                            jumpToOrder: true, // 跳转到指定页
                            showNowAndAll: true, // 当前页/共几页
                            prev: "上一页",
                            next: "下一页",
                            clickEvent: function (currectPage, _this) {
                                _readpagedata(currectPage);
                            }
                        });
                    }
                }
            });
        }

        function _showpagedata(datas) {

            $("table").find("tbody").empty();

            var hstr = "";
            for (var k = 0; k < datas.length; k++) {
                var item = datas[k];
                var htmlStr = '<tr class="text-c">';

                if (item.service) {
                    if (!item.service.isEnable) {
                        htmlStr = '<tr class="text-c disenable">';
                    }
                }

                htmlStr += '<td>' + item.id + '</td>';
                htmlStr += '<td  class="fleft">' + item.service.project.name + '(' + item.service.project.code + ')-' + item.service.name + '(' + item.service.code + ')</td>';
                htmlStr += '<td>' + item.code + '</td>';
                htmlStr += '<td>' + item.desc + '</td>';
                htmlStr += '<td>' + item.numFailedResize + '/' + item.numResize + '</td>';
                htmlStr += '<td>' + item.numFailedUpdate + '/' + item.numUpdate + '</td>';
                htmlStr += '<td><input type="button" dataid="' + item.id + '" onclick="_linuxlist(this);" value="分布"></td>';//分布 分布在哪几台服务器上
                htmlStr += '<td><input type="button" dataid="' + item.id + '" onclick="_resizerun(' + item.id + ');" value="伸缩"></td>';//分布 分布在哪几台服务器上
                htmlStr += '<td><a title="编辑" href="javascript:;" onclick="_showedit(\'编辑\',\'view.html\',\'' + item.id + '\',\'80%\',\'80%\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a></td>'
                if (item.service.fileModel != 0) {
                    htmlStr += '<td><input type="button" dataid="' + item.id + '" onclick="openselectstore(this);" value="构建并升级"></td>';//分布 分布在哪几台服务器上
                } else {
                    htmlStr += '<td></td>';//分布 分布在哪几台服务器上
                }
                htmlStr += '<td><input type="button" dataid="' + item.id + '" onclick="_modelupdate(this);" value="重新发布"></td>';//分布 分布在哪几台服务器上

                htmlStr += '</tr>';
                hstr += htmlStr;
            }
            $("table").find("tbody").append(hstr);
        }


        var selectmodelid = 0;

        function openselectstore(elc) {
            var dataid = $(elc).attr("dataid");
            selectmodelid = parseInt(dataid);
            // _showedit("选择仓库", "../storeinfo/index.html?model=select", "0", "80%", "80%");
            _apipost("/api/spider/manage/buildImage?storeid=0&modelid=" + selectmodelid, true, "", function (code, obj) {
                                if (code == 200) {
                                    layer.msg("构建新的镜像的命令已经发送，可以前往任务列表中查看任务执行结果！");
                                }
                            });
        }

        //服务器分布列表
        function _linuxlist(elc) {
            var dataid = $(elc).attr("dataid");
            _showedit("分布服务器列表", "bindlinux.html", dataid, "80%", "80%");
        }

        function _modelupdate(elc) {
            var dataid = $(elc).attr("dataid");
            _apipost("/api/spider/manage/ServiceUpdate?modelid=" + dataid, "", function (code, obj) {
                if (code == 200) {
                    layer.msg("用最新版本重新发布的任务已经提交!");
                }
            });
        }

        //选择缩放运行的容器量
        function _resizerun(id) {
            _apiget("/api/spider/manage/ReadModelRunLinux?modelid=" + id, true, function (code, obj) {

                if (code == 200) {

                    var listhtml = "";
                    for (var k = 0; k < obj.length; k++) {
                        var item = obj[k];
                        listhtml += '<tr><td>' + item.linuxid + '</td><td><span dataid="' + item.linuxid + '" class="linuxselect minbtn">' + item.name + '</span></td><td>' + item.minnum + '</td><td>' + item.runnum + '</td><td>' + item.maxnum + '</td></tr>';
                    }

                    var vboxbody = '<div class="dialogbox">'
                        + '<table>'
                        + '<thead>'
                        + '<tr>'
                        + '<th>服务器ID</th><th>服务器</th><th>最小运行</th><th>当前运行</th><th>最大运行</th>'
                        + '</tr>'
                        + '</thead>'
                        + '<tbody>'
                        + listhtml
                        + '</tbody>'
                        + '</table>'
                        + '<div><span>当前选定服务器：</span><span class="selectlinuxid" dataid="0">全部</span></div>'
                        + '<div class="inputline"><span>申请数量:</span><input type="number" class="inputsearch inputnum"><input type="button" class="btn btnresize" value="提交"></div>'
                        + '</div>';

                    layer.open({
                        type: 1,
                        title: "伸缩容器数量",
                        closeBtn: 1,
                        shadeClose: true,
                        isOutAnim: true,
                        area: '600px',
                        shade: 0.7,
                        id: 'layerchangepass',
                        resize: false,
                        btnAlign: 'c',
                        moveType: 1,//拖拽模式，0或者1
                        content: vboxbody,
                        success: function (layero, index) {
                            var btn = layero.find('.inputline');
                            var _asknum = layero.find('.inputnum');
                            var _linuxid = layero.find(".selectlinuxid");
                            layero.find(".linuxselect").click(function () {
                                var dataid = $(this).attr("dataid");
                                $(_linuxid).attr("dataid", dataid);
                                $(_linuxid).html($(this).html());
                                //取消选定
                            });
                            //取消按钮事件
                            //确认按钮点击事件
                            btn.find('.btnresize').click(function () {
                                var linuxid = $(_linuxid).attr("dataid");
                                var _num = $(_asknum).val();
                                _apipost("/api/spider/Manage/ResizeApp?modelid=" + id + "&num=" + _num + "&linuxid=" + linuxid, true, '', function (code, obj) {
                                    if (code == 200) {
                                        layer.msg("提交伸缩任务成功，请前往任务列表查看");
                                    }
                                    layer.close(index);
                                });
                                // layer.close(index);
                            })
                        }
                    });

                }

            });


        }

    </script>


</body>

</html>